<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_MngFunc.php";
	require_once "../../_func/_Validation.php";
	require_once "../../_func/_CodeFunc.php";
	
	if ( ValidCheck_isSelfRequest($_SERVER['HTTP_REFERER']) ) {
		if ( $mode == 'u' ) {
			//get parameter
			$jbnh_name 			= $param->getString('jbnh_name');
			$nhcode_item1 		= $param->getString('nhcode_item1');
			
			//공백허용하지 않는것을 먼저 등록하여 유효성 검사
			$update_arr = array(
				'jbnh_name'			=> $jbnh_name,
			);
			$isValid = true;
			foreach( $update_arr as $key => $val )
			{
				if (!ValidCheck_isNotEmpty($val)) {
					errMsg($VALIDATE_ERROR_MESSAGE);
					$isValid = false;
				}
			}
			
			//품목체크여부 검사
			if ( $isValid && ($nhcode_item1 != null) && ($nhcode_item1 != "") )
				$isValid = true;
			else
				$isValid = false;
				
			if ( !$isValid )
				errMsg("품목을 체크해 주세요");
			else
			{
				//농협정보 수정
				$result	= NHUpdate( $update_arr, $jbnh_seq);
				
				//품목삭제
				if( $result )
					$result = NHCodeDelete($jbnh_seq);

				//품목 등록
				if( $result )
				{
					$result = NHCodeDelete($jbnh_seq);
					
					if ( is_array( $nhcode_item1 ) ) {
						foreach( $nhcode_item1 as $key => $val )
						{
							$sub_arr = array(
								'jbnh_seq'		=> $jbnh_seq,
								'nhcode_item1'	=> $val,
							);		
							NHCodeInsert($sub_arr);
							unset($sub_arr);
						}
					}
					cacheControl(0);
					ob_clean();
					jserrorPop("수정되었습니다.", true, true);
				}
			}
		}
		else {
			errMsg("비정상적인 접근입니다.");
		}
	} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>코드등록</title>
<link href="/css/layout.css" type="text/css" rel="stylesheet" />
<script src="/js/mng.js"></script>
<script type="text/javascript">
	$(document).ready(function() {

		//품목리스트를 체크한다.
		fncNHCodeCheck( $('#nhcode_item1List').val() );

		
		jQuery.validator.setDefaults({
			onkeyup:false,
			onclick:false,
			onfocusout:false,
			showErrors:function(errorMap, errorList){
				$(errorList[0].element).focus();
				alert(errorList[0].message);
			}
		});
		$("#frm").validate({
			rules: {
				jbnh_name:			{required: true},
				"nhcode_item1[]":	{required: true}
			},
			messages: {
				jbnh_name:			{required: "농협명을 입력하세요"},
				"nhcode_item1[]":	{required: "품목을 체크하세요"}
			},
			success: function(label) {
				$('#sbmtBtn').remove();
			}
		});


		
	});
</script>
</head>

<?
		$jbnh_seq = $param->getString("chkbxNo");
		
		$row =& GetNHInfo($jbnh_seq);
		
		if ( $row == null )
			jserror("정보가 없습니다.");
		else
		if ( $row != null  )
		{
			$jbnh_seq	         = $row->getString('jbnh_seq');
			$jbnh_name			 = $row->getString('jbnh_name');
?>
<body class="pop">
<p class="codetitle"><span>코드등록</span></p>
    <div class="memoplace">
<form name=frm id=frm method="POST" action="<?echo $PHP_SELF?>">
        <table cellpadding="0" cellspacing="1" border="0" class="bbsTable">
          <colgroup>
          <col width="120px" />
          <col width="*" />
          </colgroup>
          <tr>
            <th>농협명</th>
            <td><input type="text" id="jbnh_name" name="jbnh_name" value="<?echo $jbnh_name?>" title="농협명"  class="boxinput w97p"/></td>
          </tr>
		  <tr>
            <th>품목</th>
            <td>
<?
			$nhcode_item1List = GetNHCodeListHTML($jbnh_seq); //1,3,..
	
			$list = Code_GetSelect('A', '1', null);
			
			if ($list->getLength() > 0 )
			{
				while ($list->hasNext())
				{
					$row 			= & $list->next();
					$code_code1		= $row->getString('CODE_CODE1');
					$code_name		= $row->getString('CODE_NAME');
?>
				<input type="checkbox" id="nhcode_item1[]" name="nhcode_item1[]" value="<?echo $code_code1?>" /> <?echo $code_name?>
<?
				}
			?>
				<input type=hidden value="<?echo $nhcode_item1List?>" id="nhcode_item1List" name="nhcode_item1List" >
			<?
			}
		}
?>
			</td>
          </tr>
        </table>
        <div class="BtnList">
            	<ul>
                	<li><input type="submit" id="sbmtBtn" name="sbmtBtn" class="btn_submit" value=""/></li>
					<li><input type="button" class="btn_cancel" onClick="MNG.fncRtnfunc('rst','NH');" title="취소"/></li>
					<input type="hidden" name="mode" id="mode" value="u"/>
					<input type="hidden" name="jbnh_seq" id="jbnh_seq" value="<?echo $jbnh_seq?>"/>
                </ul>
            </div>
</form>
	</div>
</body>
</html>
<?
	}
?>